package com.example.liunanxin.lnx226ordering.model;



import com.example.liunanxin.lnx226ordering.beans.CollectBean;
import com.example.liunanxin.lnx226ordering.iface.CollectListListener;
import com.example.liunanxin.lnx226ordering.iface.CollectListiface;
import com.example.liunanxin.lnx226ordering.retrofitservice.CollectService;
import com.example.liunanxin.lnx226ordering.url.Url;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class CollectListModel implements CollectListiface {
    private Retrofit retrofit;

    public CollectListModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Url.USERURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getCollectList(int user_id,int flag,final CollectListListener collectListListener) {
        CollectService collectService=retrofit.create(CollectService.class);
        Call<List<CollectBean>> call=collectService.getCollectList(user_id, flag);
        call.enqueue(new Callback<List<CollectBean>>() {
            @Override
            public void onResponse(Call<List<CollectBean>> call, Response<List<CollectBean>> response) {
                if (response.isSuccessful()&&response!=null){
                    collectListListener.onResponse(response.body());
                }
                else collectListListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<CollectBean>> call, Throwable t) {
                collectListListener.onFail(t.toString());

            }
        });
    }
}
